package com.handpay.zztong.hp.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import se.krka.kahlua.vm.LuaTable;

import com.handpay.framework.LuaTableUtil;
import com.handpay.zztong.hp.log.HPLog;
import com.handpay.zztong.hp.main.model.RateList;

public class Rates implements Serializable {

    private static final long serialVersionUID = -1122576365916220535L;
    private int items = 0;
    private ArrayList<Rate> rates = new ArrayList<Rate>();
    private boolean isRateNull = true;
    private int selectIndex = Rate.INVALID_ISPUBLICCHAREGE_ID;

    public int getSelectIndex() {
        return selectIndex;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public ArrayList<Rate> getRates() {
        return rates;
    }

    public void setRates(ArrayList<Rate> rates) {
        this.rates = rates;
    }

    public boolean isRateNull() {
        return isRateNull;
    }

    public void setRateNull(boolean isRateNull) {
        this.isRateNull = isRateNull;
    }

    public int getItems() {
        return items;
    }

    public void setItems(int items) {
        this.items = items;
    }

//	public static Rates generateRates(byte[] data, boolean isDataCompile) {
//		Rates rates = new Rates();
//		LuaTable luaTable = LuaTableUtil.stringToLuaTable(data, isDataCompile);
//		rates.items = (Double) luaTable.rawget("items");
//		if (rates.items <= 0) {
//			return rates;
//		}
//		rates.isRateNull = false;
//		LuaTable list = (LuaTable) luaTable.rawget("list");
//		Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
//		rates.rates = Rate.generateListRates(dataList);
//		return rates;
//	}

    public static Rates generateRates(RateList rateList) {
        Rates rates = new Rates();
//		LuaTable luaTable = LuaTableUtil.stringToLuaTable(data, isDataCompile);

        rates.items = rateList.getItems();
        if (rates.items <= 0) {
            return rates;
        }
        rates.isRateNull = false;
        List<RateList.ListBean> dataList = rateList.getList();
//		Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
        rates.rates = Rate.generateListRates(dataList);
        return rates;
    }

    //生成测试数据
    public static Rates generateTestRates(){
        Rates rates = new Rates();
        rates.items =4;
        if (rates.items <= 0) {
            return rates;
        }
        rates.isRateNull = false;
        List<RateList.ListBean> dataList = new ArrayList<>();
        for(int i=0;i<=rates.items-1;i++){
            RateList.ListBean lb=new RateList.ListBean();
            lb.setRateCode(String.valueOf(i));
            lb.setRateName("费率费率费率费率费率费率费率"+i);
            lb.setRateAmount("1000");
            lb.setIsDefault(i==0?"1":"0");
            lb.setIsPublicCharge("1");
            dataList.add(lb);
        }
        HPLog.i(HPLog.TAG_RESULT,"-----generateTestRates---dataList.size:"+dataList.size());
//		Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
        rates.rates = Rate.generateListRates(dataList);
        return rates;
    }

}
